package org.bugjail.servlet.form.edit;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.bugjail.data.TestRound;
import org.bugjail.dataaccess.DAOFactory;
import org.bugjail.servlet.BasicUIServlet;

/**
 * Servlet implementation class for Servlet: NewSuiteFormServlet
 * 
 */
public class EditTestRoundFormServlet extends BasicUIServlet {

	static final long serialVersionUID = 1L;

	private TestRound testRound;

	@Override
	protected void write(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		PrintWriter pw = response.getWriter();

		pw.println("<form method='post' action='EditTestRoundServlet'>");
		pw
				.println("Test round name:<br><input type='text' name='name' maxlength='50' value='"+testRound.getName()+"' /><br>");
		pw.println("<input type=hidden name='testroundid' value='"
				+ testRound.getId() + "' />");
		pw.println("<br><input type=submit value='Update' />");
		pw.println("&nbsp;<a href='TestRoundServlet?testcycleid="+testRound.getTestCycle().getId()+"'>Cancel</a>");
		pw.println("</form>");
	}

	@Override
	protected String pageTitle() {
		return "Edit test round";
	}

	@Override
	protected void beforeAction(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		int testroundid = Integer.parseInt(request.getParameter("testroundid"));
		testRound = DAOFactory.getDAOFactory().getTestRoundDAO().retrieveById(testroundid);
	}
}